<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>01_构造函数模式</title>
</head>

<body>
    <script type="text/javascript">
        var p = {
            name: 'Tom',
            age: 12,
            setName: function (name) {
                this.name = name
            }
        }

        var p2 = {
            name: 'Tom',
            age: 12,
            setName: function (name) {
                this.name = name
            }
        }

        //工厂模式
        function createPerson(name, age) {
            var obj = {
                name: name,
                age: age,
                setName: function (name) {
                    this.name = name
                }
            }
            return obj

        }
        var p1 = createPerson('Tom', 12)
        var p2 = createPerson('Bob', 13)

        //自定义构造函数模式
        function Person(name, age) {
            this.name = name
            this.age = age
            this.setName = function (name) {
                this.name = name
            }
        }

        var p1 = new Person('Tom', 12)
    </script>
</body>

</html>